import { read } from 'xlsx'
import * as ExcelIO from '@grapecity/spread-excelio'

export const readWorkbookShJS = (arrayBuffer, readOpt) => {
  return read(arrayBuffer, readOpt)
}

export const readSheetShJS = (arrayBuffer, readOpt, sheetName) => {
  return readWorkbookShJS(arrayBuffer, readOpt).Sheets[sheetName]
}

export const downloadWorkbook = async (workbook) => {
  const excelIO = new ExcelIO.IO()
  const json = JSON.stringify(workbook.toJSON())
  excelIO.save(json, blob => {
    saveAs(blob, `核价单-${new Date().toLocaleTimeString()}.xlsx`)
  }, function(e) {
    console.log(e)
  }, {
    xlsxStrictMode: false
  })
}